package com.example.teaching_server.controller;

import com.example.teaching_server.common.ApiResponse;
import com.example.teaching_server.dto.TimelineItemDTO;
import com.example.teaching_server.service.TimelineService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@Slf4j
@RestController
@RequestMapping("/api/timeline")
@RequiredArgsConstructor
@Tag(name = "时间轴管理", description = "活动时间轴数据查询接口")
public class TimelineController {
    private final TimelineService timelineService;

    /**
     * 获取活动时间轴数据
     */
    @GetMapping
    @Operation(summary = "获取时间轴数据", description = "根据活动ID获取时间轴相关数据")
    public ApiResponse<List<TimelineItemDTO>> getTimeline(
            @Parameter(description = "活动ID")
            @RequestParam Long activityId) {

        log.info("开始获取时间轴数据: activityId={}", activityId);

        try {
            List<TimelineItemDTO> timelineData = timelineService.getTimelineData(activityId);
            log.info("成功获取活动{}的{}条时间轴数据", activityId, timelineData.size());
            return ApiResponse.success("时间轴数据获取成功", timelineData);
        } catch (Exception e) {
            log.error("获取时间轴数据失败: activityId={}", activityId, e);
            return ApiResponse.fail("获取时间轴数据失败: " + e.getMessage());
        }
    }
}
